<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>忘记密码</title>
    <link href="css/reset-password.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" href="plugins/elementui/index.css"/>
    <script src="plugins/jquery/dist/jquery.min.js"></script>
    <script src="plugins/vue/vue.js"></script>
    <script src="plugins/vue/axios-0.18.0.js"></script>
    <script src="plugins/elementui/index.js"></script>
    <script src="plugins/healthmobile.js"></script>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<!--container-->
<div class="container" id="app">
    <div class="content">

        <div class="checksum-form">
            <label class="checksum-label">输入手机号</label>
            <input type="text" placeholder="请输入手机号" class="checksum-input" v-model="orderInfo.telephone" id="telephone"/>
            <input style="font-size: 20px;" id="validateCodeButton" @click="sendValidateCode()" type="button"
                   value="发送验证码"><br/><br/>
            <label class="checksum-label">输入验证码</label>
            <input type="text" placeholder="请输入验证码" class="checksum-input" v-model="orderInfo.validateCode"
                   id="validateCode"/><br/><br/>
            <label class="checksum-label">输入新密码</label>
            <input type="password" placeholder="请输入新密码" class="checksum-input" v-model="orderInfo.tbPassword"  id="tbPassword"/>
            <br/>
            <br/>
            <label class="checksum-label">确认新密码</label>
            <input type="password" placeholder="请再次输入新密码" class="checksum-input" v-model="orderInfo.RetbPassword"  id="RetbPassword"/>
            <div id="msg" class="warn"></div>
            <button type="submit" @click="submitEdit()" class="checksum-btn">确认修改</button>
        </div>
    </div>

</div>

<script type="text/javascript">
    $("#RetbPassword").blur(function () {
        if ($("#tbPassword").val() == "" || $("#RetbPassword").val() == "") {
            alert('请输入内容');
            return;
        }
        let $tbPassword = $("#tbPassword").val();
        let $RetbPassword = $("#RetbPassword").val();
        if ($tbPassword != $RetbPassword) {
            alert("两次输入的密码不一致");
            $("#msg").html("两次输入的密码不致，请重新输入");
        } else {
            alert('新密码设置成功');
            $("#msg").html("");
        }
    });
    $(".checksum-btn").click(function () {
        if ($.trim($('#tbPassword').val()).length <= 0 || $.trim($('#RetbPassword').val()).length <= 0) {
            $("#msg").html("请输入密码");
        }
    });
</script>
</body>
<script>
    let vue = new Vue({
        el: '#app',
        data: {
            orderInfo:{}
        },
        methods: {
            //发送验证码
            sendValidateCode() {
                //获取用户输入的手机号
                let telephone = $("#telephone").val();
                //调用js方法，校验输入的手机号是否合法
                if (!checkTelephone(telephone)) {
                    //校验不通过，提示错误信息
                    this.$message.error("请输入正确的手机号");
                    return false;
                }
                //在按钮上显示30秒倒计时效果
                validateCodeButton = $("#validateCodeButton")[0];//锁定dom对象
                clock = window.setInterval(doLoop, 1000);//定时器方法，可以实现每隔指定的时间调用指定的方法
                //发送ajax请求，为用户发送手机验证码
                axios.post("/validateCode/send4EditPwd.do?telephone=" + telephone)
                    .then((res) => {
                        if (!res.data.flag) {
                            //短信验证码发送失败
                            this.$message.error(res.data.message);
                        }
                    });
            },
            submitEdit() {
                //获取用户输入的手机号
                let telephone = $("#telephone").val();
                //调用js方法，校验输入的手机号是否合法
                if (!checkTelephone(telephone)) {
                    //校验不通过，提示错误信息
                    this.$message.error("请输入正确的手机号");
                    return false;
                }
                //发送ajax请求，提交表单数据到后台进行业务处理
                axios.post("/user/submit.do" ,this.orderInfo)
                    .then((res) => {
                        if (res.data.flag) {
                            //修改成功,跳到登录页面
                            window.location.href = "login.html";
                        } else {
                            //修改失败，提示信息
                            this.$message.error(res.data.message);
                        }
                    });
            }
        }
    });
</script>
</html>